<template>
  <div style="width: 80%">
    <div style="margin-bottom: 30px">编辑用户</div>
    <el-form :inline="true" :model="form" label-width="100px">
      <el-form-item label="图片标题">
        <el-input v-model="form.typename" placeholder="请输入图片标题" style="width: 175px"></el-input>
      </el-form-item><br/>
      <el-form-item label="封面" prop="cover">
        <el-upload
            class="avatar-uploader"
            :action="'http://localhost:9090/type/file/upload'"
            :show-file-list="false"
            :on-success="handleCoverSuccess"
        >
          <img v-if="form.timageurl" :src="form.timageurl" class="avatar">
          <i v-else class="el-icon-plus avatar-uploader-icon"></i>
        </el-upload>
      </el-form-item>
    </el-form>

    <div style="text-align: center; margin-top: 30px">
      <el-button type="primary" @click="save" size="medium">提交</el-button>
    </div>
  </div>
</template>

<script>
import request from "@/utils/request";

export default {
  name: 'EditType',
  data() {
    return {
      form: {

      }
    }
  },
  created() {
    const id = this.$route.query.id
    request.get("/type/" + id).then(res => {
      this.form = res.data
    })
  },
  methods: {
    save() {
      request.put('/type/update', this.form).then(res => {
        if (res.code === '200') {
          this.$notify.success('更新成功')
          this.$router.push("/typeList")
        } else {
          this.$notify.error(res.msg)
        }
      })
    }
  }
}

</script>
